﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace S2_Xxxx_XxxNetApi
{
    public static class SessionHelper
    {
        /// <summary>
        /// 设置Session
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        public static void SetString(ControllerBase controllerBase, string key, string value)
        {
            controllerBase.HttpContext.Session.SetString(key, value);
        }

        /// <summary>
        /// 设置Session
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        public static void SetInt32(ControllerBase controllerBase, string key, int value)
        {
            controllerBase.HttpContext.Session.SetInt32(key, value);
        }

        /// <summary>
        /// 获取Session
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>返回对应的值</returns>
        public static string GetString(ControllerBase controllerBase, string key)
        {
            var value = controllerBase.HttpContext.Session.GetString(key);
            if (string.IsNullOrEmpty(value))
                value = string.Empty;
            return value;
        }

        /// <summary>
        /// 获取Session
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>返回对应的值</returns>
        public static int? GetInt32(ControllerBase controllerBase, string key)
        {
            return controllerBase.HttpContext.Session.GetInt32(key);
        }
    }
}
